<?php
    require_once('page_base_jectly.php');

	/*
     * sub classes of page_base_jectly will include only the changes from index_2;
	 */
	class activate extends page_base_jectly {

        function __construct() {
            parent::__construct();
            $this->bool_main_menu_on=true;
            $this->bool_main_logo_on=true;
            $this->bool_search_tab_on=false;
            $this->bool_main_3boxes_on=true;
            $this->bool_search_result_within_page_on=false;
            $this->bool_account_menu_on=false;
            $this->bool_contents_area_on=false;
        }

        protected $activate_key;
        protected $contents_html;

        protected function check_query_string()
        {
            $this->activate_key=QApplication::QueryString('c');

            if(!empty($this->activate_key))
            {
                $user_tmp_=TableUserProjectTmp::LoadObjectByUrl($this->activate_key,null);

                if(isset($user_tmp_))
                {
                    $this->bool_main_3boxes_on=false;
                    $this->bool_contents_area_on=true;

                    //$this->contents_html=QApplication::Translate('<div class="center">'.$uset_tmp_.'</div>');

                    if(sizeof($user_tmp_)===0)
                    {
                        $this->contents_html=QApplication::Translate('<div class="center">the code don\'t exist</div>');
                    }
                    else
                    {
                        //registration here
                        $user_tmp_[0]->Registered='y';
                        $user_tmp_[0]->RegisterDate=QDateTime::Now();
                        
                        $new_user_=new TableuserProject();
                        $new_user_->Id=0;
                        $new_user_->UserName=$user_tmp_[0]->UserName;
                        $new_user_->Mail=$user_tmp_[0]->Mail;
                        $new_user_->Password=$user_tmp_[0]->Password;
                        $new_user_->UserType=0;
                        $new_user_->UserLevel=0;
                        $new_user_->BoothCount=0;
                        $new_user_->PortfolioCount=0;
                        $new_user_->PointBalance=0;
                        $new_user_->PointInTotal=0;
                        $new_user_->PointOutTotal=0;
                        $new_user_->PointChargedTotal=0;
                        $new_user_->RegisterDate=QDateTime::Now();
                        $new_user_->Active='y';
                        $new_user_->Suspended='n';
                        
                        $new_user_->Save();
                        $user_tmp_[0]->Save();
                        
                        $this->contents_html=QApplication::Translate('<div class="center">Hello,'.$new_user_->UserName.'! Your account is activated now. Please login.</div>');
                        
                    }
                }
                else
                {
                    $this->bool_contents_area_on=true;

                    $this->contents_html=QApplication::Translate('<div class="center">the code don\'t exist</div>');
                }
            }
            else
            {
                $this->bool_contents_area_on=true;

                $this->contents_html=QApplication::Translate('<div class="center">This page is for email confirmation.<br />Please check your email for the registration.</div>');
            }
        }

        public function render_contents_area() {

            if($this->bool_contents_area_on)
            {
                echo($this->contents_html);
            }
        }

	}

    activate::Run('activate','activate.tpl.php');

?>